package Dao;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

    public class DBUtils {
        public static Connection getConn() {
            Connection conn = null;
            try {
                Driver.class.forName("com.mysql.cj.jdbc.Driver");
                conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/newsdb?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8", "root", "123456");
            }catch (ClassNotFoundException e) {
                e.printStackTrace();
            }catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;
        }
        public static void close(ResultSet rs,PreparedStatement ps,Connection conn) {
            try {
                if(rs != null)
                    rs.close();
                if(ps != null)
                    ps.close();
                if(conn != null)
                    conn.close();
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
